#!D:/CODE/python
# -*- coding: utf-8 -*-
# @Time : 2020/5/23 22:16
# @Author : Alexdong
# @Site : 
# @File : 进程间通信.py
# @Software: PyCharm
# Functional description:Queue队列实现进程间通信
from multiprocessing import Queue
import multiprocessing
import time

def download_from_web(q):
    '''模拟从网上下载数据'''
    data = [11, 22, 33, 44, 55]
    for temp in data:
        q.put(temp)
    print("下载数据完毕，并且存入队列")

def analysis_data(q):
    '''数据处理'''

    waitting = list()
    while True:
        data = q.get()
        waitting.append(data)
        if q.empty():
            break
        print(waitting)

def main():

    # 创建一个队列
    q = multiprocessing.Queue(4)

    p1 = multiprocessing.Process(target=download_from_web, args=(q,))
    p2 = multiprocessing.Process(target=analysis_data, args=(q,))
    p1.start()
    p2.start()


if __name__ =="__main__":
    main()